package com.testes.umov.screens;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.testes.umov.R;
import com.testes.umov.model.Item;

public class ItemAdapter extends ArrayAdapter<Item> {

	private Context context;
	private int layoutResourceId;
	private Item items[] = null;
	private int iconColor, backGroundColor, textColor;
	
	public ItemAdapter(Context context, int textViewResourceId, Item[] items, int iconColor, int backGroundColor, int otherTextColor) {
		super(context, textViewResourceId, items);
		this.context = context;
		this.layoutResourceId = R.layout.activity_template_list_row;
		this.items = items;
		this.iconColor = iconColor;
		this.backGroundColor = backGroundColor;
		this.textColor = otherTextColor;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		
		if(row == null) {
			LayoutInflater inflater = ((Activity)context).getLayoutInflater();
			row = inflater.inflate(this.layoutResourceId, parent, false);
			row.setBackgroundColor(this.backGroundColor);
			
			ImageView imageView = (ImageView)row.findViewById(R.id.listItem_imageView);			
			switch(iconColor) {
				case 1:
				{
					imageView.setImageResource(R.drawable.list_item);
					break;
				}
				case 2:
				{
					imageView.setImageResource(R.drawable.list_item_white);
					break;
				}
				case 3:
				{
					imageView.setImageResource(R.drawable.list_item_black);
					break;
				}
				case 4:
				{
					imageView.setImageResource(R.drawable.list_item_gray);
					break;
				}
				default:
				{
					imageView.setImageResource(R.drawable.list_item);
				}
				
			}						
			
			TextView textView = (TextView)row.findViewById(R.id.listItem_textView);
			textView.setText(this.items[position].getDescription());
			textView.setTextColor(this.textColor);
			
			ImageButton imageButton = (ImageButton)row.findViewById(R.id.listItem_imageButton);
			imageButton.setImageResource(R.drawable.cancel);
		}
		
		return row;
	}
}
